package example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author guoq.z
 * @date 2021/3/16
 */
@RestController("/redis")
public class RedisController {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @GetMapping("/getKeys")
    public void getKeys() {
        Set<String> keys = redisTemplate.keys("SAAS_UPDATE_ORG_SEND_VEGETABLE:*");
        for (String key : keys) {
            String s = redisTemplate.opsForValue().get(key);
            System.out.println(s);
        }

    }

    @GetMapping("/putKeys")
    public void putKeys() {
        redisTemplate.opsForValue().set("SAAS_UPDATE_ORG_SEND_VEGETABLE:zhang", "fjaiodjfkladsjfklsdajflk");
    }

    @GetMapping("/delKeys")
    public void delKeys() {
        Set<String> keys = redisTemplate.keys("SAAS_UPDATE_ORG_SEND_VEGETABLE:*");
        redisTemplate.delete(keys);
    }
}
